<template>
  <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
    <!-- <div class="p10">
            <order-piece v-for="item in 3" :key="item.id" />
    </div>-->
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
      class="p10"
    >
      <order-piece v-for="item in orderList" :key="item.id" :orderParam="item" />
    </van-list>
  </van-pull-refresh>
</template>
<script>
import { ordersIndex } from "@/api/products.js";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      isLoading: false,
      finished: false,
      page: 0,
      orderList: [],
      loading:false
    };
  },
  computed: {
    ...mapGetters(["userId", "token"])
  },
  methods: {
    getOrderList() {
      //获取订单列表
      this.isLoading = false;
      let params = {
        page: this.page,
        user_id: this.userId
      };
      ordersIndex(params).then(res => {
        // eslint-disable-next-line
        console.log(res);
        this.finished = true;
        this.isLoading = false;
        this.loading = false;
        let orderArr = [];
        res.map(data => {
          data.order_details.map(e => {
            e.order_num = data.order_num;
            let myTime = e.pay_tm ? e.pay_tm : e.rec_tm
            e.pay_tm = myTime.substring(0, 10);
            orderArr.push(e);
          });
        });
        this.orderList = orderArr;
      });
    },
    onRefresh() {
      //下拉刷新
      this.page = 1;
      this.getOrderList();
    },
    onLoad() {
      //上拉加载
      this.page++;
      this.getOrderList();
    }
  },
  mounted() {
    // this.onRefresh()
  },
  components: {
    OrderPiece: () => import("./components/OrderPiece")
  }
};
</script>